/*
 * @Author: 吴华胜 765510616@qq.com
 * @Date: 2023-04-15 11:28:25
 * @LastEditors: 吴华胜 765510616@qq.com
 * @LastEditTime: 2023-04-17 14:10:32
 * @FilePath: \jshERP-web\src\utils\print\defaultPrint.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

/**
 * @file 打印
 * 指令`v-print`,默认打印整个窗口
 * 传入参数`v-print="'#id'"` , 参数为需要打印局部的盒子标识.
 */
 'use strict';

 Object.defineProperty(exports, "__esModule", {
   value: true
 });
 var {addPrintHistory} = require('@/api/api');
 var {message} = require('ant-design-vue');
 
 var _printarea = require('vue-print-nb-jeecg/lib/printarea.js');
 
 var _printarea2 = _interopRequireDefault(_printarea);
 
 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
 exports.default = {
   directiveName: 'print',
   bind: function bind(el, binding, vnode) {
     var vue = vnode.context;
     var closeBtn = true;
     el.addEventListener('click', function (event) {
       if(binding.value){
        if(vue.printDirectiveData.printType==1){
          if (binding.value) {
            localPrint();
          } else {
            window.print();
          }
          return;
        }
        addPrintHistory(vue.printDirectiveData).then(res=>{
            if(res.code == 200){
                if (binding.value) {
                  localPrint();
                } else {
                  window.print();
                }
                
            }else{
                message.error(res.message || res.data.message)
            }
        })
       }
     });
 
     var localPrint = function localPrint() {
       vue.$nextTick(function () {
         if (closeBtn) {
           closeBtn = false;
           var print = new _printarea2.default({
             el: binding.value.id || binding.value,
             endCallback: function endCallback() {
               closeBtn = true;
             }
           });
         }
       });
     };
   },
   update: function update(el, binding) {
   },
   unbind: function unbind(el) {}
 };